﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="Treasury", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(Treasury))]
    public class TreasurySerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected ITreasury clazz;
        
        public TreasurySerializer(ITreasury clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("DocumentNum");
            if (clazz.DocumentNum!=null) {
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", ">>Treasury>DocumentNum");
                Writer.WriteString(clazz.DocumentNum.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : DocumentNum");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("OrderNum");
            if (clazz.OrderNum!=null) {
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", ">>Treasury>OrderNum");
                Writer.WriteString(clazz.OrderNum.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : OrderNum");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("BankRef");
            if (clazz.BankRef!=null) {
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", ">>Treasury>BankRef");
                Writer.WriteString(clazz.BankRef.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : BankRef");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "DocumentNum")) {
                goto DocumentNum;
            }
            else {
                if ((Reader.LocalName == "OrderNum")) {
                    goto OrderNum;
                }
                else {
                    if ((Reader.LocalName == "BankRef")) {
                        goto BankRef;
                    }
                    else {
                        return;
                    }
                }
            }
        DocumentNum:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Treasury>DocumentNum");
            }
            clazz.DocumentNum = new Treasury.DocumentNumType(Reader.ReadElementString("DocumentNum"));
            goto START;
        OrderNum:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Treasury>OrderNum");
            }
            clazz.OrderNum = new Treasury.OrderNumType(Reader.ReadElementString("OrderNum"));
            goto START;
        BankRef:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Treasury>BankRef");
            }
            clazz.BankRef = new Treasury.BankRefType(Reader.ReadElementString("BankRef"));
            goto START;
        }
    }
}
